<template>
  <view v-if="cart.length!==0">
    <my-address></my-address>
    <view class="cart-titel">
      <uni-icons type="shop" size="18"></uni-icons>
      <text class="cart-titel-text">购物车</text>
    </view>
    <!--   <block v-for="(item,i) in cart" :key='i'>
      <my-goods :goods='item' :show-radio='true' @radio-change="radioChangeHandle" :show-num='true'
        @num-change="numberChangeHeadler"></my-goods>
    </block> -->
    <uni-swipe-action>
      <block v-for="(item,i) in cart" :key='i'>
        <!-- 基础用法 -->
        <uni-swipe-action-item :right-options="options"  @click="swipeActionClickHeadler(item,$event)"
          @change="change">
          <my-goods :goods='item' :show-radio='true' @radio-change="radioChangeHandle" :show-num='true'
            @num-change="numberChangeHeadler"></my-goods>
        </uni-swipe-action-item>
      </block>
    </uni-swipe-action>
    <my-swttle></my-swttle>
    
  </view>
  <!-- 空白购物车 -->
  <view class="empty-cart" v-else>
    <image src="../../static/cart_empty@2x.png" class="empty-img"></image>
    <text class="tip-text">空空如也~~</text>
  </view>
</template>

<script>
  import badgeMix from "../../mixins/tabbar-badge.js"
  import {
    mapState,
    mapMutations
  } from 'vuex'
  export default {
    mixins: [badgeMix],
    data() {
      return {
        options: [{
            text: '删除',
            style: {
              backgroundColor: '#c00000'
            }
          },
          {
            text: '取消',
            style: {
              backgroundColor: '#1296db'
            }
          }
        ]
      }
    },
    methods: {
      ...mapMutations('m_cart', ['updateGoodsState', 'updateGoodsCount',"removeGoodsById"]),
      radioChangeHandle(e) {
        console.log(e)
        this.updateGoodsState(e)
      },
      numberChangeHeadler(e) {
        console.log(e)
        this.updateGoodsCount(e)
      },
      swipeActionClickHeadler(goods,$event) {
        if($event.content.text==='取消'){
          return
        }
        console.log(goods)
        console.log($event)
        this.removeGoodsById(goods.goods_id)
      },
      change() {

      }
    },
    computed: {
      ...mapState('m_cart', ['cart'])
    },
    onShow() {}
  }
</script>

<style lang="scss">
  .cart-titel {
    height: 80rpx;
    display: flex;
    align-items: center;
    font-size: 28rpx;
    padding-left: 10rpx;
    border-bottom: 2rpx solid #efefef;

    .cart-title-text {
      margin-left: 20rpx;
    }
  }
  .empty-cart{
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 300rpx;
    .empty-img{
      width: 180rpx;
      height: 180rpx;
    }
    .tip-text{
      font-size: 24rpx;
      color: gyay;
      margin-top: 30rpx;
    }
  }
</style>
